package com.dianganjiao.lib.behavior

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.view.ViewPropertyAnimator
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.interpolator.view.animation.FastOutSlowInInterpolator

class FloatFabBehavior(context: Context?, attrs: AttributeSet?) :
    CoordinatorLayout.Behavior<View>(context, attrs) {

    private var viewY = 0.0f //控件距离coordinatorLayout底部距离
    private var isHideAnimate = false//隐藏动画是否在进行
    private var isShowAnimate = false//显示动画是否在进行
    private var isChildTop = true//判断控件是否回到原始位置
    private var animator: ViewPropertyAnimator? = null
    private val INTERPOLATOR = FastOutSlowInInterpolator()
    private var distanceY = 0

    fun setDY(distanceY: Int) {
        this.distanceY = distanceY
    }


    override fun onStartNestedScroll(
        coordinatorLayout: CoordinatorLayout,
        child: View,
        directTargetChild: View,
        target: View,
        axes: Int,
        type: Int
    ): Boolean {
        if (child.isShown && viewY == 0.0f) {
            //获取控件距离父布局（coordinatorLayout）底部距离
            viewY = coordinatorLayout.getHeight() - child.getY()

        }
        return super.onStartNestedScroll(
            coordinatorLayout,
            child,
            directTargetChild,
            target,
            axes,
            type
        )
    }

}